local IconTemplate = class("IconTemplate")
local TypeHelper = require("utils.TypeHelper")

function IconTemplate:ctor()
end

function IconTemplate:setCallback(callback)
    self._callback = callback
end

function IconTemplate:awake()
    self._postEvent = self._imageBg.gameObject:GetComponent(typeof(CS.GuidePostEvent))
    self._postEvent:SetCallback(handler(self, self._onImageIconClick))
end

function IconTemplate:updateUI(type, value, size)
    local param = TypeHelper.getRes(type, value)
    self._param = param
    self._imageBg.sprite = param.icon_bg
    self._imageIcon.sprite = param.icon
    self._imageIcon.gameObject:SetActive(true)
    if size and size > 0 then
        self._textCount.gameObject:SetActive(true)
        self._textCount.text = size
    else
        self._textCount.text = 0
        self._textCount.gameObject:SetActive(false)
    end
end

function IconTemplate:getItemParam()
    return self._param
end

function IconTemplate:showCount(show)
    self._textCount.gameObject:SetActive(show)
end

function IconTemplate:updateEmpty()
    self._imageIcon.gameObject:SetActive(false)
    self._textCount.text = ""
end

function IconTemplate:_onImageIconClick(event)
    printDebug("IconTemplate:_onImageIconClick " .. event)
    if event == 3 then
        if self._callback then
            self._callback()
        else
            if self._param then
                local pop = require("view.popup.PopupItemTips").new(self._param)
            end
        end
    end
end

return IconTemplate
